package dao;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;





import javax.persistence.TypedQuery;

import entity.Association;
import entity.Employee;
import entity.Union;
import entity.UnionDue;

@Stateless
public class UnionDueDao {
	@PersistenceContext
	EntityManager manager;

	public UnionDue CreateUnionDao(Date date, float amount,
			Union union) {
		UnionDue due = new UnionDue(date, amount, union);
		manager.persist(due);
		return due;
	}
	public List<UnionDue> ListUnionDueEmployee(Employee employee){
		if(employee.getAssociation() instanceof Union){
			String jpql="select u from UnionDue u where union_Id='"+((Union)employee.getAssociation()).getId()+"'";
			TypedQuery<UnionDue> query=manager.createQuery(jpql,UnionDue.class);
			return query.getResultList();
		}else{
			return null;
		}
			
	}
	public int removeUnionDue(UnionDue unionDue){
		try {
			UnionDue unionD=manager.merge(unionDue);
			manager.remove(unionD);
		} catch (Exception e) {
			return -1;
		}
		return 0;
	}

}
